﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Think.Lenovo.Com.DataAccess;
using System.Data;
using Think.Lenovo.Com.Models.Material;
using Think.Lenovo.Com.Models;
using Think.Lenovo.Com.DataAccess.User;

namespace Think.Lenovo.Com
{
    public partial class MaterialAddToDistributor : System.Web.UI.Page
    {
        MaterialInfo minfo = new MaterialInfo();
        MaterialBulletin model = new MaterialBulletin();
        ReceiveMaterial RM = new ReceiveMaterial();
        UserInfo info = new UserInfo();
        ReceiveMaterialInfo RMinfo = new ReceiveMaterialInfo();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString.Count > 0)
            {
                int id = Int32.Parse(Request.QueryString["id"].ToString());
                DataSet ds = new DataSet();
                ds = minfo.GetMaterialById(id);
                if (!IsPostBack)
                {
                    //  txt_title.Text = ds.
                }
            }
        }

        protected void btn_add_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            model.Title = txt_title.Text;
            model.MaterialClass = "";
            model.MaterialNum = "";
            model.Content = editor.Value;
            model.ReleaseTime = DateTime.Now;

            long MaterialBulletin_Id = minfo.AddMaterial(model);

            if (MaterialBulletin_Id > 0)
            {
                ////物料添加成功后,给选中的分区的每个分销商发送通知
                //foreach (ListItem item in this.cbl_region.Items)
                //{
                //    if (item.Selected == true)
                //    {
                for (int j = 0; j < info.GetUserIdByRegionLevelCount(3, 3); j++)
                {
                    RM.MaterialBulletin_Id = Int32.Parse(MaterialBulletin_Id.ToString());
                    RM.Receive = 0;
                    RM.UserId = Int32.Parse((info.GetUserIdByRegionLevel(3, 3)).Tables[0].Rows[0][j].ToString());
                    //RM.RegionId = Int32.Parse(item.Value);

                    RMinfo.AddReceiveMaterial(RM);
                }
                //    }
                //}
                Response.Write("<script>alert('添加成功');location.href=location.href;</script>");
            }
        }

        protected void Add_Click(object sender, EventArgs e)
        {

        }
    }
}